<?php
/**
 * 资金流水类
 * @author 孙银川
 * @date   2017.12.29
 */

namespace app\common\model;
use think\Model;

class MoneyWater extends Model{

    protected $pk = 'mw_id';
	/**
     * 所有流水数据
     */
	public function enquiries($num, $map=[]){
		// 关联用户表、商户表、代理商表
		$data = db('money_water')
			->alias('m')
			->leftJoin('user u','m.mw_user_id=u.id')
			->leftJoin('shops s','m.mw_shop_id=s.sp_id')
			->leftJoin('agent_manage a','m.mw_agem_id=a.agem_id')
			->field('m.mw_id,m.mw_user_id,m.mw_money,m.mw_create_time,u.nick_name,s.sp_name,a.agem_principals')
			->where($map)
			->paginate($num);
		// 统计
		$data->count = db('money_water')->alias('m')->where($map)->count();
		// 分页
		$data->page = $data->render();

		return $data;
	}

	/**
     * 流水详情
     */
	public function detail($id){
		$data = db('money_water')
			->alias('m')
			->join('user u','m.mw_user_id=u.id')
			->join('shops s','m.mw_shop_id=s.sp_id')
			->join('agent_manage a','m.mw_agem_id=a.agem_id')
			->field('m.*,u.nick_name,s.sp_name,a.agem_principals')
			->where('m.mw_id='.$id)
			->find();
		return $data;
	}
}
?>